using UnityEngine;
using UnityEngine.UI;
using Utils;

namespace Game.UI {
	public sealed class Checkbox : MonoBehaviour {
		public Button Button;
		public Image CheckboxImage;
		public Sprite OffSprite;
		public Sprite OnSprite;

		public EventBus<bool> OnCheckboxClicked = new EventBus<bool>();

		bool _state;

		public void SetupState(bool state) {
			_state = state;
			CheckboxImage.sprite = state ? OnSprite: OffSprite;
		}

		private void Awake() {
			Button.onClick.AddListener(OnButtonClick);
		}

		void OnButtonClick() {
			_state = !_state;
			OnCheckboxClicked.Fire(_state);
			CheckboxImage.sprite = _state ? OnSprite : OffSprite;
		}
	}
}
